/*
 * Copyright 2009 Johnson Consulting Services
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * 
 */
package com.johnsoncs.gwt.widgets.samples.client;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.johnsoncs.gwt.widgets.client.dynamictable.DynamicTable;
import com.johnsoncs.gwt.widgets.client.dynamictable.TableDefinition;
import com.johnsoncs.gwt.widgets.client.dynamictable.TableModel;
import com.johnsoncs.gwt.widgets.client.dynamictable.TableDefinition.SelectionMode;
import com.johnsoncs.gwt.widgets.client.dynamictable.models.CachedTableModel;
import com.johnsoncs.gwt.widgets.samples.client.mock.MockFilter;
import com.johnsoncs.gwt.widgets.samples.client.mock.MyRowObject;
import com.johnsoncs.gwt.widgets.samples.client.mock.MyTableDefinition;
import com.johnsoncs.gwt.widgets.samples.client.mock.MyTableModel;

/**
 * @author wilj
 *
 */
public class SimpleTableDemo extends Composite {
	boolean initialized = false;
	private final SelectionMode selectionMode;
	private final boolean showHeader;
	private final boolean showFooter;
	final FlowPanel panel = new FlowPanel();

	public SimpleTableDemo(final SelectionMode selectionMode, final boolean showHeader, final boolean showFooter) {
		this.selectionMode = selectionMode;
		this.showHeader = showHeader;
		this.showFooter = showFooter;
		super.initWidget(panel);
	}

	public void onShow() {
		if (!initialized) {
			initialized = true;
			final TableModel<MyRowObject> model = new CachedTableModel<MyRowObject>(new MyTableModel(), 500);
			model.setFilter(new MockFilter());

			final TableDefinition<MyRowObject> definition = new MyTableDefinition(selectionMode);

			definition.setShowHeader(showHeader);
			definition.setShowFooter(showFooter);

			final DynamicTable<MyRowObject> table = new DynamicTable<MyRowObject>(10, definition, model);
			final TableStatusWidget<MyRowObject> status = new TableStatusWidget<MyRowObject>(table);
			panel.add(table);
			panel.add(status);

		}
	}
}
